package edu.zju.gis.dldsj.config;

import edu.zju.gis.dldsj.base.BaseMapper;
import edu.zju.gis.dldsj.model.Jsonable;
import edu.zju.gis.dldsj.utils.SpringUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Map;

/**
 * @author yanlo yanlong_lee@qq.com
 * @version 1.0 2018/09/10
 */
@Component
@ConfigurationProperties(prefix = "data")
@Getter
@Setter
public class DataConfig {
    private Map<String, String> table2mapper;
    private Map<String, String> table2model;

    public BaseMapper<? extends Jsonable, ? extends Serializable> getMapper(String table) throws ClassNotFoundException {
        Class<? extends BaseMapper<? extends Jsonable, ? extends Serializable>> clz = (Class<? extends BaseMapper<? extends Jsonable, ? extends Serializable>>) Class.forName(table2mapper.get(table));
        return SpringUtil.getBean(clz);
    }

    public Class<? extends Jsonable> getModel(String table) throws ClassNotFoundException {
        return (Class<? extends Jsonable>) Class.forName(table2model.get(table));
    }
}
